package com.yuanqunsoft.alimigration.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.yuanqunsoft.alimigration.model.Module;
import com.yuanqunsoft.alimigration.service.IModuleService;
import com.yuanqunsoft.alimigration.utils.JsonResult;

public class ModuleAction extends ActionSupport {
    private IModuleService moduleService;
    private boolean success;
    private String errorMsg;
    private JsonResult result;
    private String appId;
    private String modId;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public JsonResult getResult() {
        return result;
    }

    public void setResult(JsonResult result) {
        this.result = result;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public IModuleService getModuleService() {
        return moduleService;
    }

    public void setModuleService(IModuleService moduleService) {
        this.moduleService = moduleService;
    }

    public String getModId() {
        return modId;
    }

    public void setModId(String modId) {
        this.modId = modId;
    }

    public String moduleList() {
        List<?> moduleList = this.getModuleService().findByApplicationId(Integer.parseInt(appId));
        setResult(new JsonResult(moduleList, moduleList.size()));
        this.setSuccess(true);
        return SUCCESS;
    }

    public String deleteModule() {
        Module instance = this.getModuleService().findById(Integer.parseInt(modId));
        this.getModuleService().deleteModule(instance);
        this.setSuccess(true);
        return SUCCESS;
    }

}
